package com.zombie.logic.object.ai;

import com.zombie.Constants;
import com.zombie.logic.object.GameObject;
import com.zombie.logic.object.LiveObject;
import com.zombie.logic.object.ai.action.Action;
import com.zombie.util.ThreadPoolManager;

public abstract class AI implements Runnable {

	LiveObject owner;

	public Action action;

	Action next;

	Action previous;
	
	public AI(LiveObject owner){
		this.owner = owner;
		ThreadPoolManager.getInstance().scheduleGeneral(this, 0);
	}
	
	@Override
	public void run() {
		if (action == null)
			spawned();
		action.checkCondition(this, owner);
		if (action.done){
			action.done = true;
			actionDone(action);
		}
//		if (action.endTime != -1 && action.endTime < GameState.time){
//			action.done = true;
//			actionDone(action);
//		}
//		if (action.done)
//			actionDone(action);
		
		if (!owner.isDead())
			ThreadPoolManager.getInstance().scheduleGeneral(this, Constants.TIMER_AI);
	}
	
	public abstract void onHit(GameObject damager);
	public abstract void doDie(GameObject killer);
	public abstract void actionDone(Action action);
	public abstract void spawned();	


	protected void setAction(Action next) {
		previous = action;
		action = next;
	}
}
